package agents;

import java.util.Random;

import main.SOSCarParkServer;
import model.agent.Agent;

public class CarGeneratorAgent extends Agent {
	
	private static final Random RANDOM = new Random(System.currentTimeMillis());
	
	/**
	 * Constructor
	 */
	public CarGeneratorAgent(String id) {
		super(id);
		initInt("i",0);
	}
	
	/**
	 * This method is generate a car and its number on the license plate randomly. 
	 * 
	 * @return a boolean
	 */
	public String getNewCarId() {

		String id = "";
		for (int i = 0; i < 3; i++) {
			id = id + (char)(RANDOM.nextInt(26)+'A');
		}
		id = id + "-";
		for (int i = 0; i < 3; i++) {
			id = id + (RANDOM.nextInt(10));
		}
		return id;
	}
	
	@Override
	public void act() throws Exception {
		//AgentCollectionStorageMySQL agentCollectionStorageMySQL = new AgentCollectionStorageMySQL();
		//agentCollectionStorageMySQL.putAgent(new CarAgent(getNewCarId()));
		SOSCarParkServer.getInstance().getAgentCollection().put(new CarAgent(getNewCarId()));
	}
}
